/**
 * 
 */

function login_frm()
{
    var un=document.loginfrm.username.value;
    var pwd=document.loginfrm.password.value;
    if(un!="")
    {
        if(pwd!="")
        {
            return true;
            document.loginfrm.submit();
        }
        else
        {
            alert("Password shouldn't be blank");
            document.loginfrm.password.focus();
            return false;
        }
    }
    else
    {
        alert("Username shouldn't be blank");
        document.loginfrm.username.focus();
        return false;
    }
}

function logoff_frm()
{
    document.loginfrm.action="./LogOff";
    document.loginfrm.submit();
}

function toggle_user() {
    document.signup.fullname.value='';
    document.signup.username.value='';
    document.signup.password.value='';
    document.signup.stream.options[0].selected=true;
    document.signup.year.options[0].selected=true;
    document.signup.subject.options[0].selected=true;
    document.signup.roll.value='';
    var result_style;
    if(document.signup.choose[0].checked) {
        result_style = document.getElementById('tr_stream').style;
        result_style.display = 'table-row';
        result_style = document.getElementById('tr_year').style;
        result_style.display = 'table-row';
        result_style = document.getElementById('tr_roll').style;
        result_style.display = 'table-row';
        result_style = document.getElementById('tr_subject').style;
        result_style.display = 'none';
        document.signup.user_type.value="Student";
    } else {
        result_style = document.getElementById('tr_stream').style;
        result_style.display = 'none';
        result_style = document.getElementById('tr_year').style;
        result_style.display = 'none';
        result_style = document.getElementById('tr_roll').style;
        result_style.display = 'none';
        result_style = document.getElementById('tr_subject').style;
        result_style.display = 'table-row';
        document.signup.user_type.value="Faculty";
    }
    document.signup.fullname.focus();
}

function noBack() {
    window.history.forward();
}

function reg_frm()
{
    var fname=document.signup.fullname.value;
    var uname=document.signup.username.value;
    var pwd=document.signup.password.value;
    var roll=document.signup.roll.value;
    if(fname=="")
    {
        document.signup.fullname.focus();
        alert("Please enter Full Name");
        return false;
    } else if(uname=="")
{
        document.signup.username.focus();
        alert("Please enter User Name");
        return false;
    } else if(uname.length<5)
{
        document.signup.username.focus();
        alert("Username shouldn't be less than 6 characters");
        return false;
    } else if(pwd=="")
{
        document.signup.password.focus();
        alert("Please enter Password");
        return false;
    } else if(pwd.length<8 || pwd.length>20)
{
        document.signup.password.focus();
        alert("Password should be 8 to 20 characters long");
        return false;
    }
    else if(document.signup.choose[0].checked)	{
        if(document.signup.stream.options[0].selected){
            document.signup.stream.focus();
            alert("Please select a stream");
            return false;
        }
        if(document.signup.year.options[0].selected){
            document.signup.year.focus();
            alert("Please select a year");
            return false;
        }
        if(roll=="")
        {
            document.signup.roll.focus();
            alert("Please enter Roll");
            return false;
        } else if(isNaN(roll) || roll ==0 || roll>99){
            document.signup.roll.value='';
            document.signup.roll.focus();
            alert("Roll can be numeric only (1<-->99)");
            return false;
        }
    } else if(document.signup.choose[1].checked)	{
        if(document.signup.subject.options[0].selected){
            document.signup.subject.focus();
            alert("Please select a subject");
            return false;
        }
    }
    return true;
}

function ques_frm()
{
    var text=document.quesForm.text.value;
    if(document.quesForm.subject.options[0].selected)
    {
        document.quesForm.subject.focus();
        alert("Please select a subject");
        return false;
    }
    else if(text=="")
    {
        alert("Question can't be blank");
        document.quesForm.text.focus();
        return false;
    } else if(text.length > 250)
    {
        alert("Question can be upto 250 characters");
        document.quesForm.text.focus();
        return false;
    }
    return true;
}

function pswd_frm(currpass)
{
    var newpass1=document.password.password2.value;
    var newpass2=document.password.password3.value;
    if(currpass!="")
    {
        if(newpass1 == "")
        {
            alert("New password shouldn't be blank");
            document.password.password2.focus();
            return false;
        } else if (newpass1.length<8 || newpass1.length>20) {
            alert("New password should be 8 to 20 characters long");
            document.password.password2.focus();
            return false;
        } else if (currpass == newpass1) {
            alert("New password shouldn't be same as current password");
            document.password.password2.focus();
            return false;
        }
        else if (newpass2 == "")
        {
            alert("Retype new password");
            document.password.password3.focus();
            return false;
        } else if(newpass1 != newpass2) {
            alert("Retype password doesn't match");
            document.password.password3.focus();
            return false;
        }
    }
    else
    {
        alert("Current password shouldn't be blank");
        document.password.password1.focus();
        return false;
    }

    return true;
}

function aprv_Form() {
    var ans=document.approval.ans.value;
    if (ans == "") {
        if(document.approval.review[0].checked) {
            alert("Please give an answer before approval.");
            document.approval.ans.focus();
            return false;
        } else {
            alert("Please give a reason for rejection.");
            document.approval.ans.focus();
            return false;
        }
    } else if (ans.length >250) {
        alert("Max 250 characters is supported");
        document.approval.ans.focus();
        return false;
    }
    return true;
}

function ans_form() {
    var ans=document.answer.ans.value;
    if(ans == "") {
        alert("Answer shouldn't be blank");
        document.answer.ans.focus();
        return false;
    } else if (ans.length >250) {
        alert("Max 250 characters is supported");
        document.answer.ans.focus();
        return false;
    }
    return true;
}